Repository navigation
Request compression - #185
Merged
Merged
Conversation
enableRequestCompression() sends request bodies of 1 KB to 1 MB compressed with gzip, once the server's SDK behavior settings answer says that it reads compressed bodies. Compression needs a build with the new CMake option COUNTLY_USE_ZLIB (off by default), which links zlib; in other builds the call logs a warning and requests stay plain. The built-in libcurl client now gives libcurl the body size, so a body with zero bytes is sent whole.
CI report
Public API changes: Public API, 0 removed or changed, 4 addedAdded: 4. Check that each one is meant to be public. Run Tests: Coverage, Line coverage 86.3%Unit test coverage
Static analysis, No new findingsclang-tidy: 74 findings
First 50 findings
New compared with the base branch: 0No finding that the base branch does not have. For f548d54, updated 2026-12-01 14:37 UTC. Each check's run page has its full log. |
Public API changesAdded: 4. Check that each one is meant to be public. |
cppcheck read the list as always empty, because the HTTP client callback fills it.
# Conflicts: # CHANGELOG.md # CMakeLists.txt # src/request_module.cpp
A local server answers the behavior settings request with gzip true. The test checks that the whole gzip body arrives, that a request without an answer keeps compression on, and that a 400 answer gives a plain retry with the same body.
…sion The header now names the rule for clients set with setHTTPClient, and the log line also fits a request that got no answer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds
enableRequestCompression(): the SDK sends request bodies of 1 KB to 1 MB compressed with gzip, following the same protocol as the other Countly SDKs.Behaviour
enableRequestCompression()beforestart().COUNTLY_USE_ZLIB(OFF by default), which links zlib. vcpkg: featurecompression. Conan: optionwith_zlib. In a build without it the call logs a warning and requests stay plain.gzip=1. The SDK compresses only after an answer with the top-level"gzip": true. The answer is kept in memory only, every answer replaces the one before, and a server URL change resets it.<endpoint>?content_encoding=gzipwith the Content-Type of the plain body and no Content-Encoding header. The request queue, the stored requests, the checksum and the logs keep the plain body."gzip": true. Network errors do not stop compression with the built-in HTTP clients. With a client set withsetHTTPClient, every failed compressed request stops it, because such a client may report no status code.setHTTPClientgets the marker at the end of the path and the gzip data asdata; it must send alldata.size()bytes.What does not change
Builds without
COUNTLY_USE_ZLIB, and apps that do not callenableRequestCompression(), send the same requests as before. The request records underapi/requests/are unchanged. No public header depends on the new definition.Public API
Countly::enableRequestCompression()CountlyConfiguration::requestCompressionEnabledRequestModule::currentServer(),RequestModule::setCompressedBodiesAccepted(bool, const std::string &)Tests
tests/request_compression.cpp, 14 test cases with zlib and 2 without:gzip=1on the behavior settings request; a large request goes compressed and decodes to the plain body, with the checksum inside; a small request stays plain"gzip": true(missing,false,"true",1, insidec) keep requests plaingzip, a server URL change, provided behavior settings and a call afterstart()gzip=1, plain requeststests/request.cpp, "Built-in HTTP client with request compression" (builds with zlib): the built-in HTTP client, libcurl or WinHTTP, againstLocalHTTPServer, which can now answer the behavior settings request with given settings and reply with 400 or with no answer:How it was checked
COUNTLY_USE_ZLIB=ON(zlib 1.3), Breakpad, SQLiteCOUNTLY_USE_ZLIB=ON(zlib 1.3.1)/i?content_encoding=gzipand decoded to 40 events with its checksum; a 400 answer gave a plain retry; an outage did not stop compression"gzip": true; the two 40-event requests went compressed (15,484 bytes as 1,125) and were answered withSuccess, the 1-event request went plain, and the server stored 81 of 81 events for each app; for the app with a salt the server accepted the checksum on the decoded bodygzip=1was answered withoutgzip, every request went plain and was answered withSuccess, and the server stored 81 of 81 events for each appBuild, packaging and CI files
CMakeLists.txt: optionCOUNTLY_USE_ZLIB,find_package(ZLIB), a private compile definition, andfind_dependency(ZLIB)in the package config.packaging/: vcpkg featurecompressionand Conan optionwith_zlib.scripts/generate_sbom.py: zlib as an optional system component..github/workflows/tests.yml: two flavors,zlibandzlib-sanitizer-asan; the coverage build turns the option on so that the new code is measured..github/workflows/static_analysis.yml: the analyzed build turns the option on so that clang-tidy sees the new code..github/workflows/packaging.ymland.github/package-check/app.cpp: the port is installed and used with thecompressionfeature, and the recipe is created withwith_zlib=True.